package com.atguigu.gmall.item.controller;

import com.atguigu.gmall.common.cache.BloomType;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.product.SpuFeignClient;
import com.atguigu.gmall.item.service.ItemService;
import org.redisson.api.RBloomFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/item")
public class SkuInfoController {

    @Autowired
    SpuFeignClient spuFeignClient;

    @Autowired
    ItemService itemService;

    @Qualifier(BloomType.SKU)
    @Autowired
    RBloomFilter<Object> skuFilter;


/*    *//**
     * 测试远程调用请求
     *//*
    @GetMapping("/hello")
    public Result<Page<SpuInfo>> hello(){

        //远程调用
        Result<Page<SpuInfo>> pageResult = spuFeignClient.spuInfoPageList(61L, 1, 10L);

        return pageResult;
    }*/

    @GetMapping("/{skuId}")
    public Result getItem(@PathVariable("skuId") Long skuId){
/*        String skuKey = RedisConst.SKUKEY_PREFIX + skuId + RedisConst.SKUKEY_SUFFIX;
        if(skuFilter.contains(skuKey)){
            //itemService 远程调用 service-product 获取到当前商品的所有详情
            Map<String, Object> skuInfo = itemService.getSkuInfo(skuId);
            return Result.ok(skuInfo);
        }*/
        //更新一次
        itemService.updateSkuHotScore(skuId);

        Map<String, Object> skuInfo = itemService.getSkuInfo(skuId);
        return Result.ok(skuInfo);
    }
}
